package com.oe.market.modules.base.model.bean;


import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.security.Timestamp;

public class RetResponse {
    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        if (msg == null || msg.isEmpty())
            this.msg = "未知错误";
        else
            this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String toString() {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("yyyy-MM-dd hh:mm:ss");
        Gson gson = gsonBuilder.create();
        return gson.toJson(this);
    }

    public boolean isOk() {
        if (code == 200) {
            return true;
        }
        return false;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    Integer code;
    String msg;
    Object data;

    public RetResponse(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static RetResponse success(){
        return success("成功");
    }
    public static RetResponse success(String msg){
        if (null == msg || msg.isEmpty())
            msg = "成功";
        return success(200,msg);
    }

    public static RetResponse success(Integer code, String msg){
        return success(code, msg, null);
    }

    public static RetResponse success(String msg, Object data){
        return success(200, msg, data);
    }

    public static RetResponse success(Integer code, String msg, Object data){
        return new RetResponse(code, msg, data);
    }




    public static RetResponse failedByAccount() {
        return failed(301, "异地登录");
    }
    public static RetResponse failedByAccountLogin() {
        return failed(301, "账号或密码错误");
    }

    public static RetResponse waring(String msg) {
        if (null == msg || msg.isEmpty())
            msg = "未知警告";
        return failed(300, msg);
    }


    public static RetResponse failed() {
        return failed("非法请求");
    }
    public static RetResponse failed(String msg) {
        if (null == msg || msg.isEmpty())
            msg = "失败";
        return failed(500, msg);
    }

    public static RetResponse failed(Integer code, String msg) {
        return failed(code, msg, null);
    }
    public static RetResponse failed(String msg, Object data) {
        return failed(500,msg, data);
    }

    public static RetResponse failed(Integer code ,String msg, Object data) {
        return new RetResponse(code, msg, data);
    }

}
